//
//  KoiArrorBackground.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 25.03.25.
//

import SwiftUI

struct KoiArrowBackground: Shape {
    
    var offset: CGFloat = 0 // 箭头在边上的偏移量
    var cornerRadius: CGFloat = 8
    var arrowSize: CGSize = CGSize(width: 15, height: 10)
    
    nonisolated func path(in rect: CGRect) -> Path {
        var path = Path()
        let paddingH = arrowSize.width / 2
        let arrowOffset = min(max(offset, cornerRadius * 2), rect.width - cornerRadius * 2)
        // 添加矩形路径
        path.addRoundedRect(in: CGRect(x: rect.minX, y: rect.minY+arrowSize.height, width: rect.width, height: rect.height-arrowSize.height), cornerSize: CGSize(width:10,height:10))
        // 绘制箭头点
        // 箭头点 1
        path.move(to: CGPoint(x: arrowOffset, y: 0))
        // 箭头点 2
        path.addLine(to: CGPoint(x: arrowOffset + paddingH, y: arrowSize.height))
        // 箭头点 3
        path.addLine(to: CGPoint(x: arrowOffset - paddingH, y: arrowSize.height))
        path.closeSubpath()
        return path
    }
}

#Preview {
    KoiArrowBackground()
}
